//
//  ZhuiJiaKuanXiangViewController.m
//  JuBoCRM
//
//  Created by iMac on 2024/10/21.
//  Copyright © 2024 iningKe. All rights reserved.
//

#import "ZhuiJiaKuanXiangViewController.h"

@interface ZhuiJiaKuanXiangViewController ()

@property (weak, nonatomic) IBOutlet NSLayoutConstraint *topSpace;
@property (weak, nonatomic) IBOutlet TPKeyboardAvoidingScrollView *mainScrollView;

@property (weak, nonatomic) IBOutlet UITextField *zhuiJiaTf;
@property (weak, nonatomic) IBOutlet UITextField *beiZhuTf;
@property (weak, nonatomic) IBOutlet UILabel *chengJiaoJinELabel;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *bottomSpace;
@property (weak, nonatomic) IBOutlet UILabel *yiFuJinELabel;
@property (weak, nonatomic) IBOutlet UILabel *shengYuJinELaebl;
@end

@implementation ZhuiJiaKuanXiangViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    
    self.customNavBar.title = @"追加款项";
    if (@available(iOS 11.0, *)) {
        self.mainScrollView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
    }
    _topSpace.constant = NavaBarHeight;
    _bottomSpace.constant = 20+ScreenBottom;
    
    _chengJiaoJinELabel.text = [NSString stringWithFormat:@"成交金额：%@",GetHandleString(_keHuDataDictionary, @"dealAmount")];
    _yiFuJinELabel.text = [NSString stringWithFormat:@"已付金额：%@",GetHandleString(_keHuDataDictionary, @"paidAmount")];
    _shengYuJinELaebl.text = [NSString stringWithFormat:@"剩余待付款金额：%.2f",[GetHandleString(_keHuDataDictionary, @"dealAmount") floatValue] - [GetHandleString(_keHuDataDictionary, @"paidAmount") floatValue]];
}
//取消
- (IBAction)quXiao:(id)sender {
    [self.view endEditing:YES];
    [self.navigationController popViewControllerAnimated:YES];
}
//确定
- (IBAction)queDing:(UIButton *)sender {
    [self.view endEditing:YES];
    if (_zhuiJiaTf.text.length == 0) {
        [ZZPUtils showWarning:_zhuiJiaTf.placeholder];
        return;
    }
    if(_zhuiJiaTf.text.floatValue > ([GetHandleString(_keHuDataDictionary, @"dealAmount") floatValue] - [GetHandleString(_keHuDataDictionary, @"paidAmount") floatValue])){
        [ZZPUtils showWarning:@"追加金额超出剩余待付款金额，请重新输入"];
        return;
    }
    NSMutableDictionary *paraDic = [NSMutableDictionary dictionary];
    [paraDic setValue:_beiZhuTf.text forKey:@"remark"];
    [paraDic setValue:_zhuiJiaTf.text forKey:@"payAmount"];
    [paraDic setValue:GetHandleString(_keHuDataDictionary, @"customerId") forKey:@"ids"];
    
    [[ZZPRequest getWebUtil] postJsonNetworkRequestURLString:@"/crmCustomer/addAmount" andParas:paraDic andShowHud:YES andTransferGottenData:^(id info, NSError *error) {
        if (!error) {
            [ZZPUtils showWarning:@"追加成功"];
            if (_manageClickBlock) {
                _manageClickBlock(0);
            }
            [self.navigationController popViewControllerAnimated:YES];
        }
    }];
    
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
